Skip to content

fix(opencode): strip tools array from cavecrew agent frontmatter#443

Open
ousamabenyounes wants to merge 1 commit into
JuliusBrussee:mainfrom
ousamabenyounes:fix/issue-386
Open

fix(opencode): strip tools array from cavecrew agent frontmatter#443
ousamabenyounes wants to merge 1 commit into
JuliusBrussee:mainfrom
ousamabenyounes:fix/issue-386

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented May 26, 2026

Copy link
Copy Markdown

Fixes #386

Summary

OpenCode rejects YAML array form tools: [...] for subagent frontmatter and refuses to boot:

Configuration is invalid at .../cavecrew-reviewer.md
↳ Expected object | undefined, got ["Read","Grep","Bash"] tools

installOpencode() in bin/install.js copied agents/cavecrew-*.md verbatim into ~/.config/opencode/agents/. Three files affected: cavecrew-investigator.md, cavecrew-builder.md, cavecrew-reviewer.md.

Fix

New helper bin/lib/opencode-agent.js exports stripOpencodeAgentTools(content) that removes the tools: line (inline-array form and multi-line YAML list form) from the leading frontmatter block. Installer's section 3 now reads β†’ strips β†’ writes instead of copyFileSync.

OpenCode allows omitting tools entirely; it then falls back to its default tool set. The cavecrew subagent prompts already self-restrict in the body ("Read-only locator", "No Bash available", etc.), so dropping the array form is safe.

Source files in agents/ are left untouched β€” they keep the Claude Code schema for the Claude Code plugin path. Transform applies only on the OpenCode copy.

Verification

Baseline (main): 47 pass / 4 fail / 51 total β€” 4 pre-existing opencode failures (caveman-compress.md missing in src/plugins/opencode/commands/, separate issue).

Post-fix: 56 pass / 4 fail / 60 total β€” 9 new tests, zero regressions, same 4 pre-existing failures.

TDD verification

  • RED check (helper missing): test file fails to import β†’ 0/1.
  • GREEN check (helper present): 9/9 pass.

Logs persisted locally in ~/.claude/contribute/working/caveman/issue_386_{RED,GREEN}.log.

Files changed

File Change
bin/lib/opencode-agent.js New. stripOpencodeAgentTools() helper.
bin/install.js Section 3 of installOpencode now sanitizes on copy.
tests/installer/opencode-agent.test.mjs New. 9 tests: inline array, multi-line list, folded description: >, no-frontmatter, no-tools, non-string, real shipped files RED/GREEN, end-to-end installer-equivalent copy.

OpenCode rejects YAML array form `tools: [Read, Grep, Bash]` on startup
(Expected object | undefined). Strip the tools line on copy into
~/.config/opencode/agents/; OpenCode falls back to default tool set and
cavecrew subagent prompts already self-restrict in the body.

Closes 386

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ousamabenyounes

Copy link
Copy Markdown
Author

Verified RED/GREEN proof (run on 8014b87 against origin/main)

Test runner: node --test tests/installer/opencode-agent.test.mjs.

Procedure:

  1. GREEN β€” full PR diff applied
  2. Replace bin/lib/opencode-agent.js with an identity stub (preserves the require resolution so unrelated tests still load, kills the strip-behavior so any test that depends on it fails)
  3. RED β€” same test file
  4. Restore helper byte-identical

GREEN (fix applied)

# tests 9
# pass 9
# fail 0

RED (helper neutered to identity)

# tests 9
# pass 4
# fail 5

The 5 failing tests on RED are precisely the ones that exercise the strip-behavior:

  • strips inline tools: [...] array from frontmatter
  • strips multi-line tools: list with indented continuation
  • preserves folded description: > continuation lines when tools: follows
  • all shipped cavecrew agent files become OpenCode-safe after transform (GREEN proof)
  • installer-equivalent copy writes OpenCode-safe agent file (issue 386 end-to-end)

The 4 tests that pass on RED are deliberate pass-through guards (no frontmatter, no tools: field, non-string input, and the RED-proof check that asserts the source agents/cavecrew-*.md files contain the offending array form β€” which is a property of the source tree, independent of the helper).

Both logs captured locally and available on request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(opencode): cavecrew agent files use invalid tools format, breaking OpenCode startup

1 participant